﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MethodWorx.CMS.TemplateParser;
using MethodWorx.CMS.Content;
using MethodWorx.CMS.Services;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using MethodWorx.CMS.Configuration;

namespace MethodWorx.CMS.UI.Areas.Application.Models
{
    public class MakePagePropertyModel
    {
        [Required(ErrorMessage="Please choose a template")]
        public PageTemplate Template { get; set; }
        public string Tag { get; set; }
        public string CssClass { get; set; }
        [Required(ErrorMessage = "Please choose a property type")]
        public string PropertyType { get; set; }
        [Required(ErrorMessage = "Please enter a property value")]
        public string PropertyValue { get; set; }
        private SchemaService service;
        private PageTemplate template;

        public MakePagePropertyModel(TemplateElement element, SchemaService service, PageTemplate template)
        {
            this.PropertyValue = element.InnerXml.Trim();
            this.Tag = element.Name.Trim();
            this.CssClass = element.GetAttributeValue("class", "", true).Trim();
            this.service = service;
            this.template = template;
        }

        public SelectList GetPageTemplates()
        {
            return new SelectList(template.GetAllInheritedTemplates(true), "Id", "Name");
        }

        public SelectList GetPropertyTypes()
        {
            var items = new PropertyConfiguration().GetPropertyConfigurations().Select(pc => pc.Name);

            return new SelectList(items);
        }

        [Required(ErrorMessage = "Please enter a property name")]
        public string PropertyName { get; set; }
    }
}